// 第一个轮播图代码
var wrap = document.querySelector(".wrap");
var next = document.querySelector(".arrow_right");
var prev = document.querySelector(".arrow_left");
next.onclick = function () {
  next_pic();
}
prev.onclick = function () {
  prev_pic();
}

function next_pic() {
  index++;
  if (index > 1) {
    index = 0;
  }
  showCurrentDot();
  var newLeft;
  if (wrap.style.left === "-300%") {
    newLeft = -200;
  } else {
    newLeft = parseInt(wrap.style.left) - 100;
  }
  wrap.style.left = newLeft + "%";
}

function prev_pic() {
  index--;
  if (index < 0) {
    index = 1;
  }
  showCurrentDot();
  var newLeft;
  if (wrap.style.left === '0px') {
    newLeft = -400;
  } else {
    newLeft = parseInt(wrap.style.left) + 100;
  }
  wrap.style.left = newLeft + "%";
}
var timer = null;

function autoPlay() {
  timer = setInterval(function () {
    next_pic();
  }, 2000);
}
autoPlay();

var container = document.querySelector(".scroll-index");
container.onmouseenter = function () {
  clearInterval(timer);
}
container.onmouseleave = function () {
  autoPlay();
}

var index = 0;
var dots = document.querySelectorAll(".buttons span");

function showCurrentDot() {
  for (var i = 0, len = dots.length; i < len; i++) {
    dots[i].className = "";
  }
  dots[index].className = "on";
}

for (var i = 0, len = dots.length; i < len; i++) {
  (function (i) {
    dots[i].onclick = function () {
      var dis = index - i;
      if (index == 1 && parseInt(wrap.style.left) !== -500) {
        dis = dis - 2;
      }
      //和使用prev和next相同，在最开始的照片5和最终的照片1在使用时会出现问题，导致符号和位数的出错，做相应地处理即可
      if (index == 0 && parseInt(wrap.style.left) !== -100) {
        dis = 2 + dis;
      }
      wrap.style.left = (parseInt(wrap.style.left) + dis * 100) + "%";
      index = i;
      showCurrentDot();
    }
  })(i);
}
// 轮播图结束

//查询点
// var find = document.getElementById('find')
// var pub = document.getElementById('pub')
// var download = document.getElementById('download')
// var findImg = document.getElementById('findImg')
// var pubImg = document.getElementById('pubImg')
// var downImg = document.getElementById('downImg')
// var p = document.querySelectorAll('.find-pub-download p')

// find.onmouseenter = function () {
//   find.style.background = '#015293'
//   findImg.src = './images/图层 94@2x.png'
//   p[0].style.color = '#fff'
// }
// find.onmouseleave = function () {
//   find.style.background = '#fff'
//   findImg.src = './images/blue.png'
//   p[0].style.color = '#015293'
// }
// pub.onmouseenter = function () {
//   pub.style.background = '#015293'
//   pubImg.src = './images/release_information1.png'
//   p[1].style.color = '#fff'
// }
// pub.onmouseleave = function () {
//   pub.style.background = '#fff'
//   pubImg.src = './images/图层 30@2x.png'
//   p[1].style.color = '#015293'
// }
// download.onmouseenter = function () {
//   download.style.background = '#015293'
//   downImg.src = './images/data _download1.png'
//   p[2].style.color = '#fff'
// }
// download.onmouseleave = function () {
//   download.style.background = '#fff'
//   downImg.src = './images/图层 63 副本@2x.png'
//   p[2].style.color = '#015293'
// }